home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: typedefs for functions??
- Date: Thu, 08 Feb 1996 14:30:39 +0200
- Organization: Carelcomp Forest
- Message-ID: <3119ECEF.3B32@cmt.lpr.mail.carel.fi>
- References: <4fa7u0$516@stork.runit.sintef.no>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- Per Henning Isaksen wrote:
- >
- > The following code works as intended, but I would like to
- > change its 'looks'.
- >
- > 1
- > 2 typedef void (*ActionFunction)(char* g);
- > 3
- > 4 void a(char* b, ActionFunction g) {
- > 5 ActionFunction p=g;
- > 6 (*p)(b);
- > 7 return;
- > 8 }
- > 9 void aa(char* g) { /* an ActionFunction */
- > 10 printf("..%s..\n", g);
- > 11 return;
- > 12 }
- > 13
- > 14
- > 15 void main() {
- > 16 a("adf", aa);
- > 17 }
- >
- > Purpose: Inside a Motif GUI, I want to pass a function that
- > can perform some action, so I have the typdef in line 2 to
- > define ActionFunction.
- >
- > I would like to change line 9 to:
- > 9 ActionFunction aa(char* g) {
- > But this causes a warning on line 16 (but it executes correctly)
- > warning 604: Pointers are not assignment-compatible.
- > warning 563: Argument #2 is not the correct type.
- >
- > Of course, I could use a cast, but I wouldn't like it.
- >
- > Anyone who can teach me the trick?
- >
- > I want to state the function
- > type (via typdefs) both in the parameter list and for the declaration
- > of the function itself. (Why? I have lots of functions and I want want
- > to mark those that are ActionFunction as such - because some change must
- > be done to all functions of this type, but not to other function of
- > similar type (i.e. void (char*) in the example)). Obviously, I could
- > use a comment, but any error that can be caught by the compiler is
- > an error I can forget.
- >
- > Per Henning
-
- At one time I did something like this:
-
- typedef void FUNCTYPE(char *g);
- typedef FUNCTYPE *FUNCPTR;
-
- FUNCTYPE aa
- {
- ...
- }
-
- and it worked just fine (FUNCTYPE aa became void aa(char *g)). But anyway, later I was told
- that it's not standardized behaviour and thus may not compile on all platforms. Using this
- example you'd use FUNCPTR (or equivalent) on your lines 4 and 5 above instead of
- ActionFunction.
-
- Later,
- AriL
- --
- All my opinions are mine and mine alone.
-